
package com.xkdx.caipiao;

import com.xkdx.caipiao.application.MyApplication;
import com.xkdx.caipiao.presistence.login.Login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class WebActivity extends Activity {

	private static final String URL_PHONE_PREFIX = "clickout";
	//protected static final String TAG = "AboutActivity";
	
	
	WebView webView;
	String www;
	Button back;
	private int CANCLE_PROGRESSBAR = 1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.web_caipiao);
		www = getIntent().getStringExtra("url");


		webView = (WebView) findViewById(R.id.webView);
		webView.loadUrl(www);
		
		webView.getSettings().setJavaScriptEnabled(true);
		
		webView.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {

				// Activity和Webview根据加载程度决定进度条的进度大小

				// 当加载到100%的时候 进度条自动消失
				// Log.i(TAG, "progress-->" + progress);
				if (progress == 100) {
					h.sendEmptyMessage(CANCLE_PROGRESSBAR);
				}
			}
			
			
		});
		

		WebSettings setting = webView.getSettings();
		webView.setWebViewClient(new webViewClient());
		setting.setBuiltInZoomControls(true);
		// webView设置自适应
		setting.setUseWideViewPort(true);
		setting.setLoadWithOverviewMode(true);
		setting.setJavaScriptEnabled(true);
		webView.requestFocus(); // 弹出输入法
	}

	Handler h = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (msg.what == CANCLE_PROGRESSBAR) {
				
			}
		}
	};

	class webViewClient extends WebViewClient {

		// 重写shouldOverrideUrlLoading方法，使点击链接后不使用其他的浏览器打开。

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {

			view.loadUrl(url);
			
			if (url.contains(URL_PHONE_PREFIX)) {
				
				//callServiceTel(tel);
				MyApplication.isClosePacketList = true;
				MyApplication.isClosePayDetail = true;
				MyApplication.isOrderPay = true;
				MyApplication.isDetails = true;
				finish();
			}
			//return super.shouldOverrideUrlLoading(view, url);

			// 如果不需要其他对点击链接事件的处理返回true，否则返回false

			return true;

		}
	}

}